package org.danysoft.encoding_converter.client;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

import org.danysoft.encoding_converter.core.CharsetRecognizer;
import org.danysoft.encoding_converter.core.ConvertHandler;
import org.danysoft.encoding_converter.core.exceptions.TooBigInputDataException;

public class Cli {

  public static void main(String[] args) {
    
    if (args.length < 3) {
      System.err.println("Too less of arguments.");
      System.err.println("Using: [inputFile] [outputFile] [charset]");
      return;
    }
    
    try {
      File inFile = new File(args[0]);
      File outFile = new File(args[1]);
      Charset charset = CharsetRecognizer.getCharsetByName(args[2]);
      
      ConvertHandler.convert(inFile, outFile, charset);
      
    } catch (IOException e) {
      System.err.print(e.getLocalizedMessage());
    } catch (TooBigInputDataException e) {
      System.err.print(e.getLocalizedMessage());
    }
    
  }

}
